void t0(){
  TFile *f = new TFile(getenv("TMP1"));
  TTree *etf = (TTree *)f->Get("etf");
  TClonesArray *tstart4 = new TClonesArray("ETFPlaHit"); // t0 daqed by F1-PXI
  TClonesArray *tstart2 = new TClonesArray("ETFPlaHit"); // t0 daqed by ETF-PXI
  TClonesArray *t0arr = new TClonesArray("ETFPlaHit"); // plastic bar array @F1
  TClonesArray *preTaTrackerX = new TClonesArray("ETFTrackTa");
  ETFPID *pid = new ETFPID();
  etf->SetBranchAddress("tstart4", &tstart4);
  etf->SetBranchAddress("tstart2", &tstart2);
  etf->SetBranchAddress("t0arr", &t0arr);
  etf->SetBranchAddress("preTaTrackerX", &preTaTrackerX);
  etf->SetBranchAddress("pid", &pid);
  TH2F *hdt2 = new TH2F("hdt2", "dtud v.s. dtlr", 500, -10., 10., 500, -10., 10.);
  TH2F *hdt24 = new TH2F("hdt24", "dtlr_f1 v.s. dtlr_etf", 500, -10., 10., 500, -10., 10.);
  TH2F *hx_f1_lr = new TH2F("hx_f1_lr", "x_f1 v.s. dtlr04", 52, -52., 52., 500, -10., 10.);
  TH2F *hx_f1_ud = new TH2F("hx_f1_ud", "x_f1 v.s. dtud04", 52, -52., 52., 500, -10., 10.);
  TH2F *hxf1_xETF = new TH2F("hxf1_xETF", "xETF v.s. xF1", 500, -45., 45., 52, -52., 52.);
  // TH2F *hxf1_xETF = new TH2F("hxf1_xETF", "xETF v.s. xF1", 36, -45., 45., 52, -52., 52.);
  TH2F *hx_f1_tof1 = new TH2F("hx_f1_tof1", "tof1 v.s. x_f1", 52, -52., 52., 1000, 120., 160.);

  const int n = etf->GetEntriesFast();
  for(int i = 0; i < n; i++){
    etf->GetEntry(i);
    double dtlr04 = -999., dtud04 = -999.;
    const int nt04 = tstart4->GetEntriesFast();
    if(2 == nt04){
      ETFPlaHit *hlr = dynamic_cast<ETFPlaHit *>(tstart4->At(0));
      ETFPlaHit *hud = dynamic_cast<ETFPlaHit *>(tstart4->At(1));
      if(4 == hlr->fired() && 4 == hud->fired()){
        dtlr04 = hlr->dt();
        dtud04 = hud->dt();
        if(-999. != dtlr04 && -999. != dtud04) hdt2->Fill(dtlr04, dtud04);
        // cout << dtl << " " << dtr << endl; // DEBUG
      } // end if
    } // end if
    
    double dtlr02 = -999.;
    const int nt02 = tstart2->GetEntriesFast();
    if(nt02){
      ETFPlaHit *hlr = dynamic_cast<ETFPlaHit *>(tstart2->At(0));
      if(4 != hlr->fired()) continue;
      dtlr02 = hlr->dt();
      // cout << dtl << " " << dtr << endl; // DEBUG
      if(-999 != dtlr04 && -999 != dtlr02) hdt24->Fill(dtlr04, dtlr02);
    } // end if

    double t0arr_pos = -999.;
    int n_t0arr_fired = 0;
    for(TObject * b : *t0arr){
      ETFPlaHit *t = dynamic_cast<ETFPlaHit *>(b);
      // t->Print(); getchar(); // DEBUG
      if(t->GetFiredStatus() == 4){
        n_t0arr_fired++;
        if(-999. == t0arr_pos) t0arr_pos = 0.;
        t0arr_pos += t->x();
        // cout << n_t0arr_fired << " " << t->x() << endl; // DEBUG
      } // end if
    } // end for over t0arr strips
    if(n_t0arr_fired){
      t0arr_pos /= n_t0arr_fired;
      if(-999. != dtlr04) hx_f1_lr->Fill(t0arr_pos, dtlr04);
      if(-999. != dtud04) hx_f1_ud->Fill(t0arr_pos, dtud04);
    } // end if

    const double tof1 = pid->tof1();
    if(tof1 > 0.){
      hx_f1_tof1->Fill(t0arr_pos, tof1); //  + 0.44088280*t0arr_pos
    } // end if

    const int n = preTaTrackerX->GetEntriesFast();
    // cout << "n: " << n << endl; getchar(); // DEBUG
    if(1 == n){
      ETFVTrack *trk = dynamic_cast<ETFVTrack *>(preTaTrackerX->At(0));
      const double xETF = trk->GetHitPos("tstop");
      // cout << "xETF: " << xETF << endl; getchar(); // DEBUG
      if(t0arr_pos) hxf1_xETF->Fill(xETF, t0arr_pos);
    } // end if

    cout << "Processing event " << i << '\r' << flush;
  } // end for over entries
  cout << endl;

  TCanvas *c = new TCanvas("c", "Plastics @ F1", 1680, 1050);
  c->Divide(3, 2);

  c->cd(1); hdt2->Draw("col");
  c->cd(2); hdt24->Draw("col");
  c->cd(3); hx_f1_lr->Draw("col");
  c->cd(4); hx_f1_ud->Draw("col");
  c->cd(6); hxf1_xETF->Draw("col");
  c->cd(5); hx_f1_tof1->Draw("col");

  // hdt2->Write("", TObject::kOverwrite);
  // hdt24->Write("", TObject::kOverwrite);
  // hx_f1_lr->Write("", TObject::kOverwrite);
  // hx_f1_ud->Write("", TObject::kOverwrite);
  // hxf1_xETF->Write("", TObject::kOverwrite);
  // hx_f1_tof1->Write("", TObject::kOverwrite);
  // f->Close();
} // end main function t0
